﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace Chap11 {
    public class PersonCollection : IEnumerable {
        private ArrayList arPeople = new ArrayList();


        // cast for Caller
        public Person GetPerson(int pos) {
            return (Person) arPeople[pos];
        }

        // Only insert Person types.
        public void AddPerson(Person p) {
            arPeople.Add(p);
        }

        public void ClearPeople() {
            arPeople.Clear();
        }

        public int Count {
            get { return arPeople.Count; }
        }

        // Foreach enumeration support
        public IEnumerator GetEnumerator() {
            return arPeople.GetEnumerator();
        }

        // Custom indexer for this class.
        public Person this[int index] {
            get { return (Person) arPeople[index]; }
            set { arPeople.Insert(index, value); }
        }
    }
}